# 定义编译器和选项
FC = gfortran
F2PY = f2py3
FFLAGS = -O2 -cpp

# 定义模块列表
# MODULES = module1 example module2 module3 moddata foo 
MODULES = $(shell /usr/bin/python3 generate_dependencies.py)
# MODULES := $(notdir $(basename $(wildcard $/*.f90)))
# 定义依赖文件
depfile = .depend

# 定义目标
.PHONY: all clean help depend

all: $(MODULES)

%:
	@echo "Building $@..."
	@$(F2PY) -m $@ -c $@.f90 > /dev/null 2>&1 || (echo "Compilation failed for $@, stopping build." && exit 1)

clean:
	@echo "Cleaning..."
	@rm -f *.so *.mod

depend: $(MODULES:=.f90)
	@echo "Generating dependencies..."
	@$(FC) $(FFLAGS) -M $^ > $(depfile)

-include $(depfile)

# 帮助目标：显示Makefile的帮助信息
help:
	@echo "可用的目标:"
	@echo "  all    - 编译所有模块"
	@echo "  $(MODULES) - 编译指定模块"
	@echo "  clean   - 清理所有编译生成的文件"
	@echo "  depend  - 自动生成依赖关系"
	@echo "  help    - 显示帮助信息"






